﻿<!DOCTYPE html>
<!--[if IE 8]> <html lang="en" class="ie8 no-js"> <![endif]-->
<!--[if IE 9]> <html lang="en" class="ie9 no-js"> <![endif]-->
<!--[if !IE]><!-->
<html lang="en" class="no-js">
<!--<![endif]-->

<head>
<meta charset="utf-8">
<title>有色废旧</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta content="width=device-width, initial-scale=1" name="viewport">
<meta content="" name="description">
<meta content="" name="author">
<script>BASE_URL ='${request.getContextPath()}'</script>
<link href="${request.getContextPath()}/Public/assets/admin/css/css.css"
	rel="stylesheet" type="text/css">
<link
	href="${request.getContextPath()}/Public/assets/global/plugins/font-awesome/css/font-awesome.min.css"
	rel="stylesheet" type="text/css">
<link
	href="${request.getContextPath()}/Public/assets/global/plugins/simple-line-icons/simple-line-icons.min.css"
	rel="stylesheet" type="text/css">
<link
	href="${request.getContextPath()}/Public/assets/global/plugins/bootstrap/css/bootstrap.min.css"
	rel="stylesheet" type="text/css">
<link
	href="${request.getContextPath()}/Public/assets/global/plugins/uniform/css/uniform.default.css"
	rel="stylesheet" type="text/css">

<link
	href="${request.getContextPath()}/Public/assets/global/css/components-rounded.css"
	id="style_components" rel="stylesheet" type="text/css">
<link
	href="${request.getContextPath()}/Public/assets/global/css/plugins.css"
	rel="stylesheet" type="text/css">
<link
	href="${request.getContextPath()}/Public/assets/admin/css/layout.css"
	rel="stylesheet" type="text/css">
<link
	href="${request.getContextPath()}/Public/assets/admin/css/themes/default.css"
	rel="stylesheet" type="text/css" id="style_color">
<link
	href="${request.getContextPath()}/Public/assets/admin/css/custom.css"
	rel="stylesheet" type="text/css">
<link
	href="${request.getContextPath()}/Public/assets/global/plugins/bootstrap-datepicker/css/bootstrap-datepicker.min.css"
	rel="stylesheet" type="text/css">

<link
	href="${request.getContextPath()}/Public/assets/admin/css/common.css"
	rel="stylesheet" type="text/css">

<link rel="shortcut icon"
	href="${request.getContextPath()}/Public/favicon.ico">
<link href="${request.getContextPath()}/Public/css/client.css"
	rel="stylesheet" type="text/css">
<link href="${request.getContextPath()}/Public/assets/global/css/kkpager.css" rel="stylesheet" type="text/css">
<link href="${request.getContextPath()}/Public/css/customerDetail.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="${request.getContextPath()}/Public/My97DatePicker/WdatePicker.js"></script>
<style type="text/css">
body {
	margin: 0;
	padding: 0;
}
/*div_Import */
#div_Import {
	position: fixed;
	z-index: 999;
	width: 600px;
	height: 400px;
	border: 1px solid #ccc;
	background: #efefef;
	display: none;
	overflow: auto;
	border-radius:10px;
}

#div_Import .tit {
	background: #ddd;
	display: block;
	height: 15px;
	width:600px;
	margin:0 auto;
}

#div_Import .tit_NC {
	background: #26a69a;
	display: block;
	height: 24px;
}

#div_Import .tit i {
	float: right;
	line-height: 15px;
	padding: 0 8px;
	cursor: pointer;
}
</style>
</head>

<body class="page-header-top-fixed">
<!--头部信息结束 -->
<div class="page-header">
	<!--头部开始-->
	<#include "/include/top.html" />
	<!-- 头部信息结束 -->


	<!-- 头部菜单开始 -->
	<#include "/include/top_menu.html" />
	<!-- 头部菜单结束 -->
</div>
	<!-- END HEADER -->

<div class="page-container">
		<!-- 内容开始 -->
		<div class="page-content">
			<div class="container-fluid">
			<ul class="page-breadcrumb breadcrumb">
					<li>
						<a href="#">首页</a><i class="fa fa-circle"></i>
					</li>
					<li class="active">
						 客户管理<i class="fa fa-circle"></i>
					</li>
					<li class="active">
						新建客户
					</li>
				</ul>
				<div class="row margin-top-10">
					<div class="portlet light">
						<h3 style="font-weight:bold;" align="center">&nbsp;&nbsp;新建客户&nbsp;&nbsp;&nbsp;&nbsp;</h3>
						<form id="form_main">
						<table class="tb" cellspacing="1" border="1" id="tb_order_detail">
							<tbody>
								<tr>
									<td class="tdTitle" width="25%">负责人</td>
									<td  id="pic" width="25%">
										<select name="pic" style="width: 50%;" class="form-control">
											<#if userList??>
											<#list userList as el> 
												<option ${(userId==el.id)?string('selected="selected"','')} value="${(el.id)!}">${(el.name)!}</option>
											</#list>
											</#if>
										</select>
									</td>
									<td class="tdTitle" width="25%">昵称</td>
									<td  id="nickName" width="25%">
						
										<input type="text" name="nickName" style="width: 50%;" class="form-control" >
									</td>
								</tr>
								<tr>
									<td class="tdTitle"><font color="red">*</font>手机</td>
									<td  >
										<input type="text" name="phone"  id="phone" style="width: 50%;" class="form-control" onblur="phoneIsExist()">
									</td>
									<td class="tdTitle"><font color="red">*</font>废旧品种</td>
									<td>
										<input onclick="showItemListView()" type="text" name="itemName" style="width: 50%;" id='itemName' class="form-control" >
										<input type="hidden" name="itemId" id="itemId"  >
									</td>
								</tr>
								<tr>
									<td class="tdTitle">姓名</td>
									<td >
										<input type="text" name="name" style="width: 50%;" id='name' class="form-control" >
									</td>
									<td class="tdTitle"><font color="red">*</font>地区</td>
									
									<td  >
									<table style="width: 50%;">
									<tr>
									<td>
									<select name="prov" id="prov" class="form-control" onchange="getCity()" style="width: 200px;">
													<option value="" >请选择</option>
													<#if areasList??>
													<#list areasList as areas>
													<option value="${areas.id?if_exists}">${areas.name?if_exists}</option>
													</#list>
													</#if>
									</select>
									</td>
									<td align="left">&nbsp;省&nbsp;</td>
									<td align="right" style="width: 200px;">	<div id="cityDiv" style="display: none"><select name="city" id="city" class="form-control" style="width: 200px;">
												</select>
												</div>
												</td>
									<td align="left"><div id="cityDiv1" style="display: none">&nbsp;市</div></td>
									</tr>
									</table>
												
									</td>
								</tr>
								<tr>
									<td class="tdTitle">公司名</td>
									<td  id="address">
										<input type="text"  id="companyName" style="width: 50%;" name="companyName" class="form-control">
									</td>
									<td class="tdTitle">地址</td>
									<td  >
									<input type="text" name="address" style="width: 50%;" id='address' class="form-control" >
									</td>
									
								</tr>
								<tr>
									<td class="tdTitle">交易类型</td>
									<td  >
										<label><input type="checkbox" name="categorybusinessCheck"   value="2">销售&nbsp;</label>
										<label><input type="checkbox"  name="categorybusinessCheck" value="1">采购</label>
										<input type="hidden"  name="categorybusiness" id="categorybusiness">
									</td>
										<td class="tdTitle">企业类型</td>
									<td  >
										<#if categoryList??>
										<#list categoryList as el> 
											<label><input type="checkbox" name ="entTypesCheck" class="form-control" value="${(el.id)!''}">&nbsp;${(el.name)!}&nbsp;</label>
										</#list>
										</#if>
										<input type="hidden"  name="entTypes" id="entTypes">
									</td>
								</tr>
								<tr>
									<td class="tdTitle">邮箱</td>
									<td  id="address">
										<input type="text" style="width: 50%;"  id="email" name="email" class="form-control">
									</td>
									<td class="tdTitle"></td>
									<td >
									</td>
								</tr>
							</tbody>
						</table>
						
						
							<div class="modal-footer" style="text-align: center;">
								<button type="button" onclick="save(0)" class="btn green">保存</button>
							<button type="button" onclick="save(1)" class="btn green">保存并新建</button> 
							<button type="button" class="btn green" data-dismiss="modal"  onclick="rtnCustomer()">返回</button> 
						<!-- 		<label>&nbsp;&nbsp;<input type="checkbox" onclick="addOrUpdate(this)">&nbsp;同时更新（注册）商城用户</label> -->
							</div>
						</form>

					
					</div>
				</div>
			</div>
		</div>
	</div>

	




	<!-- END PAGE CONTAINER -->
<!-- 底部开始 -->
<#include "/include/foot.html" />
<!-- 底部结束 -->

	
	<!--[if lt IE 9]>
<script src="${request.getContextPath()}/Public/assets/global/plugins/respond.min.js"></script>
<script src="${request.getContextPath()}/Public/assets/global/plugins/excanvas.min.js"></script>
<![endif]-->
	<script
		src="${request.getContextPath()}/Public/assets/global/plugins/jquery.min.js"
		type="text/javascript"></script>
	<script
		src="${request.getContextPath()}/Public/assets/global/plugins/jquery-migrate.min.js"
		type="text/javascript"></script>
	<script
		src="${request.getContextPath()}/Public/assets/global/plugins/jquery-ui/jquery-ui.min.js"
		type="text/javascript"></script>
	<script
		src="${request.getContextPath()}/Public/assets/global/plugins/bootstrap/js/bootstrap.min.js"
		type="text/javascript"></script>
	<script
		src="${request.getContextPath()}/Public/assets/global/plugins/bootstrap-hover-dropdown/bootstrap-hover-dropdown.min.js"
		type="text/javascript"></script>
	<script
		src="${request.getContextPath()}/Public/assets/global/plugins/jquery-slimscroll/jquery.slimscroll.min.js"
		type="text/javascript"></script>
	<script
		src="${request.getContextPath()}/Public/assets/global/plugins/jquery.blockui.min.js"
		type="text/javascript"></script>
	<script
		src="${request.getContextPath()}/Public/assets/global/plugins/jquery.cokie.min.js"
		type="text/javascript"></script>
	<script
		src="${request.getContextPath()}/Public/assets/global/plugins/uniform/jquery.uniform.min.js"
		type="text/javascript"></script>

	<script
		src="${request.getContextPath()}/Public/assets/global/plugins/jquery.sparkline.min.js"
		type="text/javascript"></script>

	<script
		src="${request.getContextPath()}/Public/assets/global/plugins/bootstrap-datepicker/js/bootstrap-datepicker.js"
		type="text/javascript"></script>

	<script
		src="${request.getContextPath()}/Public/assets/global/scripts/metronic.js"
		type="text/javascript"></script>
	<script
		src="${request.getContextPath()}/Public/assets/admin/scripts/layout.js"
		type="text/javascript"></script>
	<script
		src="${request.getContextPath()}/Public/assets/admin/scripts/indexComponent.js"
		type="text/javascript"></script>
	<script
		src="${request.getContextPath()}/Public/assets/admin/scripts/commonUtils.js"
		type="text/javascript"></script>
	<script
		src="${request.getContextPath()}/Public/assets/admin/scripts/tc.min.js"
		type="text/javascript"></script>
	<script
		src="${request.getContextPath()}/Public/assets/admin/scripts/ajaxfileupload.js"
		type="text/javascript"></script>
<script src="${request.getContextPath()}/Public/assets/global/plugins/kkpager.min.js" type="text/javascript"></script>
	<script>
	var isPhone=false;
	jQuery(document).ready(function() {
		Metronic.init(); // init metronic core componets
		Layout.init(); // init layout
	});
	function rtnCustomer(){
		window.location.href="${request.getContextPath()}/customer/customerList.do";
	}
	function showItemListView(){
		CommonUtils.editModal('${request.getContextPath()}/customer/showItemListView.do',600);
	}
	function save(type){
		var phone=$("#phone").val();
		var itemName=$("#itemName").val();
		var email=$("#email").val();
		var prov=$("#prov").val();
		var city=$("#city").val();
		//var reg = new RegExp("^[0-9]*$");
		//var tel = 18767802354;
		 var reg = /^0?1[3|4|5|8][0-9]\d{8}$/;

		if(phone!=null&&phone!=""){
			if(reg.test(phone)){
				if(isPhone==true){
					if(prov!=null&&prov!=""){
						if(prov!=1&&prov!=2&&prov!=3&&prov!=4){
							if(city==null||city==""){
								CommonUtils.succModal("系统提示",
								"地区不能为空");
								return;
							}
						}
						if(itemName!=null&&itemName!=""){
							var re3 = /^(\w-*\.*)+@(\w-?)+(\.\w{2,})+$/;
							if(email!=null&&email!=""){
								if(!re3.test(email)){
							  		CommonUtils.succModal("系统提示",
									"请输入正确邮箱格式");
							       return;
							  	  }
							}
						  	  
							loadCus();
							$.ajax({
								url : "${request.getContextPath()}/customer/addCustomer.do",
								type : "post",
								dataType : "json",
								async : false,
								data : $("#form_main").serialize(),
								success : function(result) {
									if (result.info == "success") {
										if(type=='0'){
											CommonUtils.succModal2("系统提示", "保存成功！", "${request.getContextPath()}/customer/customerList.do");
										}else{
											CommonUtils.succModal2("系统提示", "保存成功！", "${request.getContextPath()}/customer/toAddCustomer.do");
										}
									} else {
											CommonUtils.succModal("系统提示",
													"添加失败");
									} 
								}
							});
						}else{
							CommonUtils.succModal("系统提示",
							"请输入废旧品种");
						}
						
					}else{
						CommonUtils.succModal("系统提示",
						"地区不能为空");
					}
				}else{
					CommonUtils.succModal("系统提示",
					"手机号已经存在");
				}
				
			}else{
				CommonUtils.succModal("系统提示",
				"手机号格式不对！");
			}
			
			
		}else{
			CommonUtils.succModal("系统提示",
			"手机号不能为空！");
		}
		
	}
	function loadCus(){
	
				var cate=document.getElementsByName("categorybusinessCheck");
				var ent=document.getElementsByName("entTypesCheck");
				var objarrayId=cate.length;
				var objarrayId1=ent.length;
				var cateids="";
				var entids="";
				for (i=0;i<objarrayId;i++)
				{
				  if(cate[i].checked == true)
				  {
					  cateids+=cate[i].value+",";
				  }
				}
				if(cateids != "")
				{
					cateids=cateids.substr(0,cateids.length-1);
				}
				
				for (j=0;j<objarrayId1;j++)
				{
				  if(ent[j].checked == true)
				  {
					  entids+=ent[j].value+",";
				  }
				}
				if(entids != "")
				{
					entids=entids.substr(0,entids.length-1);
				}
				$("#categorybusiness").val(cateids);
				$("#entTypes").val(entids)
			
	}
	
	//根据省获取市
	function getCity(){
		var provId = $("#prov").val();
		if(provId!=''){
			if(provId!=1&&provId!=2&&provId!=3&&provId!=4){
				$('#cityDiv').css('display','block');
				$('#cityDiv1').css('display','block');
				$.ajax({  
			        url : "${request.getContextPath()}/customer/showCity.do?provId="+provId,   
			        dataType : 'json', 
					success : function(result) {
						 if(result.info=='success'){
							 var jsonData = eval(result.areasList);
							 $("#city").empty();
							$("#city").append("<option value=''>请选择</option>");
							 $.each(jsonData, function(index, areas){
									 $("#city").append(
												"<option value='"+areas.id+"' >" + areas.name + "</option>");
								
							});  
						 }else{
							 CommonUtils.succModal("系统提示", "获取失败");
						 }
			        },  
			        error : function(data)//服务器响应失败处理函数  
			        {  
			         alert("请求失败");
			        }  
			    }); 
			}else{
				$('#cityDiv').css('display','none');
				$('#cityDiv1').css('display','none');
			}
		}
		  
	}
	
	function phoneIsExist(){
		var phone = $("#phone").val();
		 $.ajax({  
		        url : "${request.getContextPath()}/customer/showPhoneExist.do?phone="+phone,   
		        dataType : 'json', 
				success : function(data) {
					 if(data.info=='success'){
						 isPhone=true;
					 }else{
						 isPhone=false;
						 CommonUtils.succModal("系统提示",data.errorMsg );
					 }
		        },  
		        error : function(data)//服务器响应失败处理函数  
		        {  
		         alert("请求失败");
		        }  
		    }); 
	}
	
	</script>

</body>
</html>